package com.zdy.boot.upload.core.job.config;

import com.zdy.boot.upload.core.job.scheduler.ScheduleManager;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Scheduler;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.Optional;

/**
 * @author sdy
 * @description
 * @date 2025/2/9
 */
@Slf4j
@Configuration
@EnableScheduling // 开启 Spring 自带的定时任务
@EnableConfigurationProperties(JobConfig.class)
public class JobConfiguration {

    @Bean
    public ScheduleManager scheduleManager(Optional<Scheduler> scheduler) {
        log.info("=====加载定时任务=====");
        if (!scheduler.isPresent()) {
            log.info("[定时任务 - 已禁用]");
            return new ScheduleManager(null);
        }
        return new ScheduleManager(scheduler.get());
    }

}
